package com.xudu.tourbackend.controller.Impl;

import com.xudu.tourbackend.common.globalEnum.ErrorCode;
import com.xudu.tourbackend.controller.RecommendController;
import com.xudu.tourbackend.entity.Element;
import com.xudu.tourbackend.entity.request.UpdateRecommendRequest;
import com.xudu.tourbackend.entity.vo.RouteVo;
import com.xudu.tourbackend.exception.ServiceException;
import com.xudu.tourbackend.service.IRecommendService;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.Collections;
import java.util.List;

/**
 * @className: RecommendControllerImpl
 * @description: TODO
 * @author: xudu
 * @create: 2024-06-24
 */
@CrossOrigin(origins = "*")
@RestController
public class RecommendControllerImpl implements RecommendController {

    @Resource
    private IRecommendService RecommendService;

    @Override
    public List<RouteVo> getRecommendRoute() {
        return RecommendService.getRecommendRoute();

    }

    @Override
    public List<RouteVo> updateRecommendRoute(@RequestBody UpdateRecommendRequest updateRecommendRequest, HttpServletRequest request) {
        List<Integer> ids = updateRecommendRequest.getIds();
        if (ids.isEmpty()){
            throw new ServiceException(ErrorCode.NULL_ERROR);
        }
        return RecommendService.updateRecommendRoute(ids, request);
    }

    @Override
    public List<Element> getRecommendElement() {
        return RecommendService.getElement();
    }

    @Override
    public List<Element> updateRecommendElement(@RequestBody UpdateRecommendRequest updateRecommendRequest, HttpServletRequest request) {
        List<Integer> ids = updateRecommendRequest.getIds();
        if (ids.isEmpty()){
            throw new ServiceException(ErrorCode.NULL_ERROR);
        }
        return RecommendService.updateElement(ids, request);
    }


}
